<?php

require('configs/include.php');

class c_registrar_temas extends super_controller {

    public function registrar() {

        //validar la categoria del obra

        $tema = new tema($this->post);
        if (is_empty($tema->get('nombre'))) { {
                throw_exception("Debe ingresar un codigo");
            }
        } else if (is_empty($tema->get('descripcion'))) { {
                throw_exception("Debe ingresar una descripcion");
            }
        } else {
            $this->orm->connect();
            $this->orm->insert_data("normal", $tema);
            $this->orm->close();

            $this->type_warning = "success";
            $this->msg_warning = "tema agregado correctamente";

            $this->temp_aux = 'message.tpl';
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
        }
    }

    public function display() {
        $this->engine->display('header.tpl');
       
        $this->engine->display('registrar_temas.tpl');
        $this->engine->display('footer.tpl');
    }

    public function run() {
        try {

            //Por que en las lineas siguientes se usa get si el metodo de envio de datos fue post?
            //diap 14
            if (isset($this->get->option)) {
                $this->{$this->get->option}();
            }
        } catch (Exception $e) {
            $this->error = 1;
            $this->msg_warning = $e->getMessage();
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
            $this->temp_aux = 'message.tpl';
        }
        $this->display();
    }

}

$call = new c_registrar_temas();
$call->run();
?>
